package Adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.linefly.online_car.R;

import java.util.List;

import Been.been_chexingxuanze;

/**
 * Created by liheng on 2018/10/6.
 */

public class Adapter_chexingxuanze extends RecyclerView.Adapter<Adapter_chexingxuanze.ViewHolder>   {

    private List<been_chexingxuanze> list1;
    private item_click item_click;

    public interface item_click{
        void itemclick(int position);
    }
    public void setItemClick(item_click itemClick){
        this.item_click = itemClick;
    }

    public Adapter_chexingxuanze(List<been_chexingxuanze> list) {
        this.list1 = list;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView textView_cx,textView_shuoming,textView_price;
        ImageView imageView_tupian;
        ViewHolder(View itemView) {
            super(itemView);
            textView_cx = itemView.findViewById(R.id.chexing);
            textView_shuoming = itemView.findViewById(R.id.shuoming);
            textView_price = itemView.findViewById(R.id.price);
            imageView_tupian = (ImageView)itemView.findViewById(R.id.tupian);


        }
    }



    @Override
    public Adapter_chexingxuanze.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rc_chexingxuanze, parent, false);
        Adapter_chexingxuanze.ViewHolder viewHolder = new Adapter_chexingxuanze.ViewHolder(view);
        return viewHolder;
    }


    @Override
    public void onBindViewHolder(Adapter_chexingxuanze.ViewHolder holder, final int position) {


        holder.textView_cx.setText(list1.get(position).getChexing());

        holder.textView_price.setText("");
//        holder.textView_shuoming.setVisibility(View.GONE);
        //设置状态
if(list1.get(position).getShuoming().equals("0")){
    //Glide.with(holder.itemView.getContext()).load(R.mipmap.car_3).into(holder.imageView_tupian);
    holder.textView_shuoming.setText("离线");
}else if(list1.get(position).getShuoming().equals("1")){
    //Glide.with(holder.itemView.getContext()).load(R.mipmap.car_0).into(holder.imageView_tupian);
    holder.textView_shuoming.setText("在线");
}else {
    //Glide.with(holder.itemView.getContext()).load(R.mipmap.car).into(holder.imageView_tupian);
    holder.textView_shuoming.setText("熄火");
}
        Glide.with(holder.itemView.getContext()).load(list1.get(position).getTupian()).into(holder.imageView_tupian);


        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item_click.itemclick(position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list1.size();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }



}
